<?php
/**
 * $Id: tagged_item.php 39 2010-10-13 11:45:07Z varun $
 * 
 * This file can not be redistributed to anyone without the permission of Giga Promoters
 * Copyright 2005 - 2008, Giga Promoters
 * 						  608 Aggarwal Cyber Plaza
 *						  Netaji Subhash Place, Delhi - 110034
 *						  www.gigapromoters.com
 * 
 *
 * @version 			$Rev: 39 $
 * @lastModifiedBy		$LastChangedBy: varun $
 * @lastChanged			$Date: 2010-10-13 17:15:07 +0530 (Wed, 13 Oct 2010) $
 * @copyright 			Giga Promoters (www.gigapromoters.com)
 * 
 */

/**
 * Model for tagged items table. This can be of use sometimes
 *
 */
class TaggedItem extends TagsAppModel
{
    var $name = 'TaggedItem';
	
	
	function getTagCount($type = null,$withSlug = null)
	{
		$conditions = array();
		$this->unbindAll();
		if($type)
		{
			$conditions  = array('type'=>$type,$type.'.status'=>1);
			$this->bindModel(array('belongsTo'=>array($type=>array('className'=>$type,'foreignKey'=>'item_id'))),false);
		}
		$this->bindModel(array('belongsTo'=>array('Tag'=>array('className'=>'Tags.Tag'))),false);
		$tags = $this->find('all',array('conditions'=>$conditions,'group'=>'tag_id','order'=>'Tag.tag','fields'=>'Tag.tag,Tag.slug,Count(TaggedItem.id) as count'));
		if(empty($tags))
		{
			return false;
		}
		$tagCount['tags'] = Set::combine($tags,'{n}.Tag.tag','{n}.0.count');
		if($withSlug)
		{
			$slugs = Set::combine($tags,'{n}.Tag.tag','{n}.Tag.slug');
			$tagCount['slugs'] =$slugs;
		}
		return $tagCount;
	}

}

?>